import QtQuick 1.0

Rectangle {
    id: background

    width: 360
    height: 640

    color: "darkgray"

    // Handle orientation switching
    // Connect the the orientation sensor signal from C++ to our handler function
    Connections {
        id: orient
        property int rotation
        target: filter // this is available only on device, on desktop you get warnings
        onOrientationChanged: {
            if (orientation === 1) {
                console.log("Orientation TOP POINTING UP");
                orient.rotation = 0
            } else if (orientation === 2) {
                console.log("Orientation TOP POINTING DOWN");
                orient.rotation = 180
            } else if (orientation === 3) {
                console.log("Orientation LEFT POINTING UP");
                orient.rotation = 270
            } else if (orientation === 4) {
                console.log("Orientation RIGHT POINTING UP");
                orient.rotation = 90
            }
        }
    }

    // States for rotating the main display rectangle
    states: [
        State {
            when: orient.rotation === 0 || orient.rotation === 180
            PropertyChanges {
                target: mainWindow
                rotation: orient.rotation
                width: background.width
                height: background.height
            }
        },
        State {
            when: orient.rotation === 90 || orient.rotation === 270
            PropertyChanges {
                target: mainWindow
                rotation: orient.rotation
                width: background.height
                height: background.width
            }
        }
    ]

    // Put your real content here and center on background
    MainWindow {
        // Use this id in orientation state changes
        id: mainWindow

        anchors.centerIn: parent
        width: parent.width
        height: parent.height

        // Animations for rotation and size changes
        Behavior on rotation { RotationAnimation { direction: RotationAnimation.Shortest; duration: 500; easing.type: Easing.OutQuint } }
        Behavior on width    { NumberAnimation   { duration: 500; } }
        Behavior on height   { NumberAnimation   { duration: 500; } }
    }
}
